{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 导入工具包（removebg.py）\n",
    "# 函数 remove_bg：去除背景， 函数 show_img：显示图片\n",
    "from removebg import remove_bg, show_img"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 展示原始图片\n",
    "\n",
    "### 将原始图片中的背景去掉，只留下狗和猫"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img_file = \"images/cat_dog.jpg\"\n",
    "show_img(img_file)  # 展示原始的输入图片"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 执行代码并展示去背景的图片\n",
    "\n",
    "### 执行前，需要获取 API Key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用前，请设置 API_KEY，需要自己去注册 https://www.remove.bg\n",
    "API_KEY = \"\"\n",
    "# 删除图片背景，no_bg_img_file 为图片路径\n",
    "no_bg_img_file = remove_bg(API_KEY, img_file)\n",
    "\n",
    "show_img(no_bg_img_file)  # 展示去除背景后的图片"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 获取 API Key 的步骤\n",
    "\n",
    "### 1. 访问 https://www.remove.bg/zh 站点\n",
    "### 2. 点击“注册”，进入创建帐号的页面\n",
    "### 3. 填写：电子邮箱、密码、密码确认，点击“注册”按钮后，将会收到一封邮件\n",
    "### 4. 登录注册的电子邮箱，点击“Activate Account” 激活帐号\n",
    "### 5. 登录  www.remove.bg  点击“我的账户”>“API密钥”>“新API密钥”\n",
    "### 6. 直接点击“创建API密钥”，点击“复制”，粘贴到代码API_KEY=\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
